<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>档案管理</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form :model="editForm" label-width="100px" ref="editForm">
          <el-form-item label="卷目名:">
            <el-input v-model="editForm.name" auto-complete="off" placeholder="填写卷目名"></el-input>
          </el-form-item>
          <el-form-item label="卷目号:">
            <el-input v-model="editForm.sn" auto-complete="off" placeholder="填写卷目号"></el-input>
          </el-form-item>
          <el-form-item label="补充用途:" prop="name">
            <el-input v-model="editForm.content" auto-complete="off" placeholder="补充用途" type="textarea"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
        <el-button size="small" type="primary" @click="editSubmit">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {files_add, files_Detail, files_edit} from '@/api/admin/badge'
export default {
  props: ['visible', 'sealId'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      editForm: {
        name:'',//  卷目名
        sn:'',// 卷目号
        content:'',//  用途
      }, // 编辑界面数据
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.sealId) {
          // this.getDetail();
        }
      } else {
        for (let i in this.editForm) {
          this.editForm[i] = '';
        }
      }
    }
  },
  created() {
  },
  methods: {
    getDetail() {
      files_Detail({id: this.sealId}).then(res=>{
        console.log('res:', res)
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 提交数据
    async editSubmit() {
      // 验证信息
      let dataOption = this.getJson(this.editForm)
      if (!dataOption.name) {
        this.$message.error('填写卷目名')
        return
      }
      // !files_add, files_Detail, files_edit
      if(!this.sealId){
        files_add(dataOption).then(res=>{
          console.log('res:', res)
          this.$emit('InitFn')
          this.closePOpup()
          this.clearnFn()
        })
      }else{
        files_edit(dataOption).then(res=>{
          console.log('res:', res)
          this.$emit('InitFn')
          this.closePOpup()
          this.clearnFn()
        })
      }
    },
    clearnFn() {
      this.editForm = {
        name:'',//  卷目名
        sn:'',// 卷目号
        content:'',//  用途
      } // 编辑界面数据
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}
</style>


